package TCP.file;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.UUID;

public class Recvice {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(10086);

        Socket socket  = serverSocket.accept();

        String s = UUID.randomUUID().toString().replace("-","");


        BufferedInputStream bufferedInputStream = new BufferedInputStream(socket.getInputStream());
        BufferedOutputStream bufferedOutputStream  = new BufferedOutputStream(new FileOutputStream(s+".png"));
        int x;
        byte[] bytes = new byte[1024];
        while ((x=bufferedInputStream.read(bytes))!=-1){
            bufferedOutputStream.write(bytes,0,x);
        }

        BufferedWriter bufferedWriter = new BufferedWriter( new OutputStreamWriter(socket.getOutputStream()));
        bufferedWriter.write("传输成功");

        bufferedWriter.newLine();
        bufferedWriter.flush();

        socket.close();

        serverSocket.close();
    }
}
